package com.suptrack.web.servlet.admin;

import java.io.IOException;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.suptrack.entity.Car;
import com.suptrack.entity.User;
import com.suptrack.service.CarService;
import com.suptrack.service.UserService;

/**
 * Servlet implementation class removeUserServlet
 */
@WebServlet("/RegisteredContent/Admin/removeUser")
public class removeUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
  @EJB
  UserService userservice;
  @EJB
  CarService carservice;
  
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		long id = Long.parseLong(request.getParameter("id2"));
		User user = userservice.getUserInfo(id);
	
		
		List<Car> listcar = user.getCar();
		for(Car car : listcar)
		{
			carservice.deleteCarService(car);
		}
		userservice.deleteUserbyId(user.getId());
		
		response.sendRedirect(request.getServletContext().getContextPath()+"/RegisteredContent/Admin");
	}

}
